<?php

require("include/top.php");
	$tpl->display("header.tpl");
    $tpl->display("menu.tpl");
	  if(isset($_SESSION['vendor'])) {	
		if(!empty($_POST['submit'])) require(FORM_PATH."inbox.form.php");	
	
  
       /* Lecture */
       if(isset($_GET['id'])) {
	   
            $message = new Message($_GET['id']);
			
			$message->read();
			
            $tpl->assign('message', $message);
			
			
            $tpl->display("inbox/view.tpl");
       }

       /* Ecriture */
       elseif(isset($_GET['write'])) {
			$users=$_SESSION['vendor']->getRelatedUsers();
			$tpl->assign('users',$users);
          
            $tpl->display("inbox/write.tpl");
       }

       /* Listing */
       else {
			if(isset($_GET['view'])){
			
			$messages=$_SESSION['vendor']->getSentMessages();
			}
			
			else {
			
			$messages=$_SESSION['vendor']->getReceivedMessages();}
		
			$tpl->assign('messages',$messages);
            $tpl->display("inbox/list.tpl");
       }

    } else {
        header("Location:login.php");
    }
$tpl->display("footer.tpl");
require("include/bottom.php");

?>